<template>
  <div class="product-management">
    <!-- 页面标题和店铺信息 -->
    <div class="page-header">
      <div class="header-content">
        <h2><i class="el-icon-goods"></i> 商品管理</h2>
        <div class="shop-info" v-if="shopId">
          <span class="product-count">共 {{ pagination.total }} 个商品</span>
        </div>
      </div>
    </div>

    <!-- 搜索筛选区域 -->
    <div class="search-container">
      <div class="search-form">
        <el-input 
          v-model="searchForm.productName" 
          placeholder="商品名称" 
          clearable
          prefix-icon="el-icon-search"
          class="search-input"
        ></el-input>
        
        <el-select 
          v-model="searchForm.categoryId" 
          placeholder="商品分类" 
          clearable
          class="search-input"
        >
          <el-option 
            v-for="category in categoryList" 
            :key="category.id" 
            :label="category.categoryName" 
            :value="category.id"
          ></el-option>
        </el-select>
        
        <el-input 
          v-model="searchForm.price" 
          placeholder="商品价格" 
          type="number"
          clearable
          class="search-input"
        >
          <template slot="prepend">¥</template>
        </el-input>
        
        <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetForm">重置</el-button>
      </div>
      
      <div class="action-buttons">
        <el-button type="primary" icon="el-icon-plus" class="btn-add" @click="handleAdd">新增商品</el-button>
        <el-button 
          type="danger"
          icon="el-icon-remove-outline"
          @click="handleBatchTakeOff"
          :disabled="!selectedIds.length"
        >
          批量下架 ({{ selectedIds.length }})
        </el-button>
      </div>
    </div>

    <!-- 商品列表 -->
    <div class="table-container">
      <el-table 
        :data="tableData" 
        style="width: 100%;"
        ref="table"
        @selection-change="handleSelectionChange"
        v-loading="loading"
        stripe
      >
        <el-table-column type="selection" width="100" align="center"></el-table-column>
        <el-table-column label="商品图片" width="100"  align="center">
          <template slot-scope="scope">
            <div class="product-image">
              <el-image 
                :src="getImageUrl(scope.row.productImage)" 
                fit="cover"
                :preview-src-list="[getImageUrl(scope.row.productImage)]"
              >
                <div slot="error" class="image-slot">
                  <i class="el-icon-picture-outline"></i>
                </div>
              </el-image>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="productName" label="商品名称" min-width="50" align="center">
          <template slot-scope="scope">
            <div class="product-name">{{ scope.row.productName }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="categoryName" label="分类" width="120"></el-table-column>
        <el-table-column prop="price" label="价格" width="100" align="center" :formatter="formatPrice"></el-table-column>
        <el-table-column prop="stock" label="库存" width="100" align="center">
          <template slot-scope="scope">
            <span :class="{'low-stock': scope.row.stock < 10}">{{ scope.row.stock }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="monthlySales" label="月销量" width="90" align="center">
          <template slot-scope="scope">
            <span class="sales-count">{{ scope.row.monthlySales || 0 }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状态" width="100" align="center">
          <template slot-scope="scope">
            <el-tag 
              :type="scope.row.status === 1 ? 'success' : 'danger'" 
              size="small"
              :effect="scope.row.status === 1 ? 'dark' : 'plain'"
            >
              {{ scope.row.status === 1 ? '上架中' : '已下架' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" width="200"></el-table-column>
        <el-table-column label="操作" width="180" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button size="mini" icon="el-icon-edit" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button 
              size="mini" 
              icon="el-icon-remove"
              type="danger"
              plain
              @click="handleTakeOff(scope.row.id)"
              :disabled="scope.row.status !== 1"
            >
              下架
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 分页 -->
    <div class="pagination-container">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pagination.currentPage"
        :page-sizes="[10, 20, 50]"
        :page-size="pagination.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pagination.total"
      ></el-pagination>
    </div>

    <!-- 商品表单弹窗 -->
    <el-dialog 
      :title="formTitle" 
      :visible.sync="dialogVisible"
      width="700px"
      :close-on-click-modal="false"
      custom-class="product-form-dialog"
    >
      <el-form 
        :model="formData" 
        :rules="formRules" 
        ref="productForm"
        label-width="100px"
        label-position="left"
      >
        <el-form-item label="商品名称" prop="productName">
          <el-input v-model="formData.productName" placeholder="请输入商品名称"></el-input>
        </el-form-item>
        
        <el-form-item label="所属分类" prop="categoryId">
          <el-select v-model="formData.categoryId" placeholder="请选择分类" style="width: 100%;">
            <el-option 
              v-for="category in categoryList" 
              :key="category.id" 
              :label="category.categoryName" 
              :value="category.id"
            ></el-option>
          </el-select>
        </el-form-item>
        
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="商品价格" prop="price">
              <el-input v-model.number="formData.price" type="number" min="0" step="0.01" placeholder="0.00">
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="库存数量" prop="stock">
              <el-input v-model.number="formData.stock" type="number" min="0" placeholder="0"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        
        <el-form-item label="商品描述" prop="description">
          <el-input v-model="formData.description" type="textarea" rows="3" placeholder="请输入商品描述"></el-input>
        </el-form-item>
        
        <el-form-item label="商品图片" prop="productImage">
          <el-upload
            action="#"
            list-type="picture-card"
            :limit="1"
            :auto-upload="false"
            :on-change="handleImageChange"
            :on-preview="handleImagePreview"
            :on-remove="handleImageRemove"
            :on-exceed="handleImageExceed"
            :file-list="imageFileList"
            :before-upload="beforeImageUpload"
            class="product-image-uploader"
          >
            <i class="el-icon-plus"></i>
            <div slot="tip" class="el-upload__tip">支持jpg/png格式，大小不超过2MB</div>
          </el-upload>
          <el-dialog :visible.sync="imageDialogVisible" append-to-body>
            <img width="100%" :src="imageDialogUrl" alt="商品图片预览">
          </el-dialog>
        </el-form-item>
        
        <el-form-item label="商品状态" prop="status">
          <el-radio-group v-model="formData.status">
            <el-radio :label="1" border>上架</el-radio>
            <el-radio :label="0" border>下架</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleSubmit" :loading="submitting">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { 
  getProductList, 
  getProductInfo, 
  addProduct, 
  updateProduct, 
  takeOffProduct, 
  batchTakeOffProduct 
} from '@/api/product/product';
import { 
  listCategory, 
} from '@/api/product/category';

export default {
  name: 'ProductManagement',
  data() {
    return {
      searchForm: {
        productName: '',
        categoryId: '',
        price: ''
      },
      tableData: [],
      categoryList: [],
      pagination: {
        currentPage: 1,
        pageSize: 10,
        total: 0
      },
      dialogVisible: false,
      formTitle: '',
      formData: {
        id: '',
        productName: '',
        categoryId: '',
        price: '',
        description: '',
        productImage: '',
        productImageFile: null,
        stock: 0,
        status: 1,
        shopId: null
      },
      formRules: {
        productName: [
          { required: true, message: '请输入商品名称', trigger: 'blur' },
          { min: 2, max: 50, message: '长度在 2 到 50 个字符', trigger: 'blur' }
        ],
        categoryId: [
          { required: true, message: '请选择商品分类', trigger: 'change' }
        ],
        price: [
          { required: true, message: '请输入商品价格', trigger: 'blur' },
          { type: 'number', message: '价格必须为数字', trigger: 'blur' },
          { validator: (rule, value, callback) => {
            if (value <= 0) {
              callback(new Error('价格必须大于0'));
            } else {
              callback();
            }
          }, trigger: 'blur' }
        ],
        stock: [
          { required: true, message: '请输入库存数量', trigger: 'blur' },
          { type: 'number', message: '库存必须为数字', trigger: 'blur' },
          { validator: (rule, value, callback) => {
            if (value < 0) {
              callback(new Error('库存不能为负数'));
            } else {
              callback();
            }
          }, trigger: 'blur' }
        ],
        productImage: [
          { required: true, message: '请上传商品图片', trigger: 'change' }
        ]
      },
      selectedIds: [],
      imageFileList: [],
      imageDialogUrl: '',
      imageDialogVisible: false,
      imageChanged: false,
      loading: false,
      submitting: false
    }
  },
  computed: {
    shopId() {
      return this.$store.state.user.shopId;
    }
  },
  watch: {
    // 监听店铺ID变化，重新加载商品列表
    shopId(newVal) {
      if (newVal) {
        this.getProductList();
        this.getCategoryList(); // 重新获取分类
      }
    }
  },
  created() {
    this.initPage();
  },
  methods: {
    async initPage() {
      // 等待店铺信息加载
      await this.waitForShopInfo();
      this.getProductList();
      this.getCategoryList();
    },
    
    waitForShopInfo() {
      return new Promise((resolve) => {
        if (this.shopId) {
          resolve();
        } else {
          const checkInterval = setInterval(() => {
            if (this.shopId) {
              clearInterval(checkInterval);
              resolve();
            }
          }, 100);
          
          setTimeout(() => {
            clearInterval(checkInterval);
            resolve();
          }, 3000);
        }
      });
    },
    
    getProductList() {
      if (!this.shopId) {
        this.$message.warning('请先登录并获取店铺信息');
        return;
      }
      
      this.loading = true;
      const params = {
        productName: this.searchForm.productName || null,
        categoryId: this.searchForm.categoryId ? Number(this.searchForm.categoryId) : null,
        price: this.searchForm.price ? Number(this.searchForm.price) : null,
        shopId: this.shopId,
        pageNum: this.pagination.currentPage,
        pageSize: this.pagination.pageSize
      }
      
      getProductList(params).then(res => {
        this.tableData = res.rows || [];
        this.pagination.total = res.total || 0;
        this.loading = false;
      }).catch(err => {
        console.error('获取商品列表失败', err);
        this.$message.error('获取商品列表失败');
        this.loading = false;
      });
    },
    
    getCategoryList() {
      if (!this.shopId) {
        this.$message.warning('请先登录并获取店铺信息');
        return;
      }
      
      // 使用独立的参数获取全部分类
      const params = {
        pageNum: 1,
        pageSize: 1000, // 设置足够大的页面大小获取全部分类
        shopId: this.shopId
      };
      
      listCategory(params).then(response => {
        if (response && response.code === 200) {
          this.categoryList = response.rows || [];
        } else {
          this.$message.error(response?.msg || '获取分类数据失败');
        }
      }).catch(error => {
        this.$message.error('加载分类数据失败：' + (error.message || error));
      });
    },
    
    handleSearch() {
      this.pagination.currentPage = 1;
      this.getProductList();
    },
    
    resetForm() {
      this.searchForm = {
        productName: '',
        categoryId: '',
        price: ''
      };
      this.pagination.currentPage = 1;
      this.getProductList();
    },
    
    handleAdd() {
      if (!this.shopId) {
        this.$message.warning('请先获取店铺信息');
        return;
      }
      
      this.formTitle = '新增商品';
      this.formData = {
        id: '',
        productName: '',
        categoryId: '',
        price: '',
        description: '',
        productImage: '',
        productImageFile: null,
        stock: 0,
        status: 1,
        shopId: this.shopId
      };
      this.imageFileList = [];
      this.imageChanged = false;
      this.formRules.productImage[0].required = true;
      this.dialogVisible = true;
      
      this.$nextTick(() => {
        if (this.$refs.productForm) {
          this.$refs.productForm.clearValidate();
        }
      });
    },
    
    handleEdit(row) {
      this.formTitle = '编辑商品';
      this.formData = {
        ...row,
        price: Number(row.price),
        stock: Number(row.stock),
        productImageFile: null,
        shopId: this.shopId
      };
      this.imageFileList = row.productImage 
        ? [{ url: this.getImageUrl(row.productImage), name: 'productImage' }] 
        : [];
      this.imageChanged = false;
      this.formRules.productImage[0].required = false;
      this.dialogVisible = true;
    },
    
    handleSubmit() {
      this.$refs.productForm.validate(valid => {
        if (valid) {
          if (!this.shopId) {
            this.$message.warning('请先获取店铺信息');
            return;
          }
          
          this.submitting = true;
          
          if (this.formData.id) {
            this.updateProduct();
          } else {
            this.addProduct();
          }
        }
      });
    },
    
    addProduct() {
      const formData = new FormData();
      formData.append('productName', this.formData.productName);
      formData.append('categoryId', this.formData.categoryId);
      formData.append('price', this.formData.price);
      formData.append('description', this.formData.description);
      formData.append('stock', this.formData.stock);
      formData.append('status', this.formData.status);
      formData.append('shopId', this.shopId);
      
      if (this.formData.productImageFile) {
        formData.append('productImage', this.formData.productImageFile);
      }
      
      addProduct(formData).then(res => {
        this.$message.success('新增成功');
        this.dialogVisible = false;
        this.getProductList();
      }).catch(err => {
        console.error('新增失败:', err);
        this.$message.error('新增失败：' + (err.message || '网络错误'));
      }).finally(() => {
        this.submitting = false;
      });
    },
    
    updateProduct() {
      const editFormData = new FormData();
      editFormData.append('id', this.formData.id);
      editFormData.append('productName', this.formData.productName);
      editFormData.append('categoryId', this.formData.categoryId);
      editFormData.append('price', this.formData.price);
      editFormData.append('description', this.formData.description);
      editFormData.append('status', this.formData.status);
      editFormData.append('stock', this.formData.stock);
      editFormData.append('shopId', this.shopId);
      
      if (this.imageChanged && this.formData.productImageFile) {
        editFormData.append('productImage', this.formData.productImageFile);
      }
      
      updateProduct(editFormData).then(res => {
        this.$message.success('修改成功');
        this.dialogVisible = false;
        this.getProductList();
      }).catch(err => {
        console.error('修改失败:', err);
        this.$message.error('修改失败：' + (err.message || '网络错误'));
      }).finally(() => {
        this.submitting = false;
      });
    },
    
    handleTakeOff(id) {
      this.$confirm('确定要下架该商品吗？下架后顾客将无法看到此商品。', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        takeOffProduct(id).then(() => {
          this.$message.success('下架成功');
          this.getProductList();
        }).catch(err => {
          this.$message.error('下架失败：' + (err.message || '网络错误'));
        });
      });
    },
    
    handleBatchTakeOff() {
      if (this.selectedIds.length === 0) {
        this.$message.warning('请先选择要下架的商品');
        return;
      }
      
      this.$confirm(`确定要下架选中的 ${this.selectedIds.length} 个商品吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        batchTakeOffProduct(this.selectedIds).then(() => {
          this.$message.success('批量下架成功');
          this.selectedIds = [];
          this.getProductList();
        }).catch(err => {
          this.$message.error('批量下架失败：' + (err.message || '网络错误'));
        });
      });
    },
    
    handleSelectionChange(selection) {
      this.selectedIds = selection.map(item => item.id);
    },
    
    handleSizeChange(val) {
      this.pagination.pageSize = val;
      this.pagination.currentPage = 1;
      this.getProductList();
    },
    
    handleCurrentChange(val) {
      this.pagination.currentPage = val;
      this.getProductList();
    },
    
    handleImageChange(file, fileList) {
      const isImage = file.raw.type.includes('image/');
      if (!isImage) {
        this.$message.error('只能上传图片文件');
        return false;
      }
      
      this.imageFileList = fileList.slice(-1);
      this.formData.productImageFile = this.imageFileList.length > 0 ? this.imageFileList[0].raw : null;
      this.imageChanged = true;
      this.$refs.productForm.validateField('productImage');
      this.formData.productImage = this.formData.productImageFile ? 'temp_value' : '';
    },
    
    beforeImageUpload(file) {
      const isImage = file.type.includes('image/');
      const isLt2M = file.size / 1024 / 1024 < 2;
      
      if (!isImage) {
        this.$message.error('只能上传图片文件');
        return false;
      }
      if (!isLt2M) {
        this.$message.error('图片大小不能超过 2MB');
        return false;
      }
      return true;
    },
    
    handleImagePreview(file) {
      this.imageDialogUrl = file.url;
      this.imageDialogVisible = true;
    },
    
    handleImageRemove(file, fileList) {
      this.imageFileList = fileList;
      this.formData.productImageFile = null;
      this.formData.productImage = '';
      this.imageChanged = true;
      this.$refs.productForm.validateField('productImage');
    },
    
    handleImageExceed() {
      this.$message.warning('最多只能上传1张商品图片');
    },
    
    formatPrice(row, column, cellValue) {
      return '¥' + (cellValue || 0).toFixed(2);
    },
    
    getImageUrl(path) {
      if (!path) return '';
      
      if (path.startsWith('http://') || path.startsWith('https://')) {
        return path;
      }
      
      if (path.startsWith('D:/ruoyi/uploadPath/')) {
        const filename = path.replace('D:/ruoyi/uploadPath/', '');
        return `http://127.0.0.1:9300/statics/${filename}`;
      }
      
      if (path.startsWith('/statics/')) {
        return `http://127.0.0.1:9300${path}`;
      }
      
      if (path && !path.includes('/') && path.includes('.')) {
        return `http://127.0.0.1:9300/statics/${path}`;
      }
      
      return path;
    }
  }
}
</script>

<style scoped>
/* 原有样式保留，仅新增/修改表格相关样式 */
.product-management {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: calc(100vh - 84px);
}

.page-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  margin-bottom: 20px;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  color: white;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
}

.page-header h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  display: flex;
  align-items: center;
}

.page-header h2 i {
  margin-right: 10px;
  font-size: 24px;
}

.shop-info {
  display: flex;
  align-items: center;
  gap: 15px;
}

.product-count {
  color: rgba(255, 255, 255, 0.9);
  font-size: 14px;
}

.search-container {
  padding: 20px;
  background: white;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.search-input {
  width: 200px;
}

.action-buttons {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  border-top: 1px dashed #e8e8e8;
  padding-top: 15px;
}

.btn-add {
  margin-left: 0;
}

/* 表格容器样式优化 */
.table-container {
  padding: 20px;
  background: white;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  margin-bottom: 20px;
  overflow: hidden; /* 防止表格边框溢出 */
}

/* 表格整体样式优化 */
:deep(.el-table) {
  --table-header-bg: #f8fafc; /* 表头背景色 */
  --table-row-hover-bg: #f0f9ff; /* 行 hover 背景色 */
  --table-border-color: #e2e8f0; /* 表格边框色 */
  --table-text-color: #334155; /* 表格文字色 */
  --table-header-text-color: #475569; /* 表头文字色 */
  
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--table-border-color);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
}

/* 表头样式优化 */
:deep(.el-table th) {
  background-color: var(--table-header-bg);
  color: var(--table-header-text-color);
  font-weight: 600;
  font-size: 14px;
  padding: 14px 12px; /* 增加表头内边距 */
  border-bottom: 2px solid var(--table-border-color);
  text-align: center !important; /* 强制表头居中 */
}

/* 表格行样式优化 */
:deep(.el-table tr) {
  height: 68px; /* 统一行高，提升美观度 */
  transition: background-color 0.2s ease;
}

/* 表格单元格样式优化 */
:deep(.el-table td) {
  color: var(--table-text-color);
  font-size: 13px;
  padding: 12px;
  border-bottom: 1px solid var(--table-border-color);
  vertical-align: middle !important; /* 强制单元格垂直居中 */
}

/* 行 hover 效果优化 */
:deep(.el-table tbody tr:hover > td) {
  background-color: var(--table-row-hover-bg) !important;
  color: #1e40af; /* hover 时文字加深 */
}

/* 表格条纹样式优化（如果开启stripe） */
:deep(.el-table--striped .el-table__body tr.el-table__row--striped td) {
  background-color: #fefeff; /* 浅色条纹，提升区分度 */
}

/* 表格选择框列样式优化 */
:deep(.el-table-column--selection) {
  width: 100px !important;
}
:deep(.el-table .el-checkbox__inner) {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border-color: #94a3b8;
}
:deep(.el-table .el-checkbox__input.is-checked .el-checkbox__inner) {
  background-color: #3b82f6;
  border-color: #3b82f6;
}
:deep(.el-table .el-checkbox__input.is-checked + .el-checkbox__label) {
  color: #3b82f6;
}

/* 商品图片单元格样式优化 */
.product-image {
  width: 54px;
  height: 54px;
  margin: 0 auto;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: transform 0.2s ease;
}
.product-image:hover {
  transform: scale(1.05); /* 图片 hover 放大效果 */
}
.product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.image-slot {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  color: #94a3b8;
  font-size: 22px;
}

/* 商品名称样式优化 */
.product-name {
  font-weight: 500;
  color: #334155;
  font-size: 13px;
  line-height: 1.5;
  max-width: 200px; /* 限制最大宽度 */
  white-space: nowrap; /* 不换行 */
  overflow: hidden; /* 隐藏溢出内容 */
  text-overflow: ellipsis; /* 省略号显示 */
  transition: color 0.2s ease;
}
.product-name:hover {
  color: #3b82f6; /* 名称 hover 变色 */
  text-decoration: underline; /* 下划线提示可交互 */
}

/* 库存状态样式优化 */
.low-stock {
  color: #ef4444;
  font-weight: 600;
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 4px;
  background-color: #fee2e2;
}

/* 销量数字样式优化 */
.sales-count {
  color: #10b981;
  font-weight: 600;
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 4px;
  background-color: #ecfdf5;
}

/* 状态标签样式优化 */
:deep(.el-table .el-tag) {
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
}
:deep(.el-table .el-tag--success) {
  background-color: #10b981;
  color: white;
}
:deep(.el-table .el-tag--danger) {
  background-color: #ef4444;
  color: white;
}

/* 操作按钮样式优化 */
:deep(.el-table .el-button--mini) {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  margin: 0 3px;
  transition: all 0.2s ease;
}
:deep(.el-table .el-button--mini:hover) {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
:deep(.el-table .el-button--mini[disabled]) {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* 分页容器样式优化 */
.pagination-container {
  padding: 15px 20px;
  background: white;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  text-align: right;
}
:deep(.el-pagination) {
  font-size: 13px;
}
:deep(.el-pagination__sizes) {
  margin-right: 10px;
}
:deep(.el-pagination button) {
  border-radius: 4px;
}
:deep(.el-pagination .el-pager li) {
  border-radius: 4px;
  margin: 0 3px;
}
:deep(.el-pagination .el-pager li.active) {
  background-color: #3b82f6;
  color: white;
}

/* 表单弹窗相关样式保留 */
:deep(.product-form-dialog) {
  border-radius: 12px;
}

:deep(.product-form-dialog .el-dialog__header) {
  border-bottom: 1px solid #e8e8e8;
  padding: 15px 20px;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4e7ed 100%);
  border-radius: 12px 12px 0 0;
}

:deep(.product-form-dialog .el-dialog__title) {
  font-weight: 600;
  color: #303133;
}

:deep(.product-form-dialog .el-dialog__body) {
  padding: 25px 20px;
}

:deep(.product-form-dialog .el-dialog__footer) {
  border-top: 1px solid #e8e8e8;
  padding: 15px 20px;
}

:deep(.product-image-uploader .el-upload) {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: border-color 0.3s;
}

:deep(.product-image-uploader .el-upload:hover) {
  border-color: #409EFF;
}

:deep(.product-image-uploader .el-upload-list__item) {
  transition: all 0.3s;
}

:deep(.product-image-uploader .el-upload-list__item:hover) {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* 响应式适配优化 */
@media (max-width: 1200px) {
  .product-name {
    max-width: 150px;
  }
}

@media (max-width: 768px) {
  .search-form {
    flex-direction: column;
    align-items: stretch;
  }
  
  .search-input {
    width: 100%;
  }
  
  .action-buttons {
    flex-direction: column;
  }
  
  /* 移动端表格优化 */
  :deep(.el-table) {
    font-size: 12px;
  }
  
  :deep(.el-table th) {
    padding: 12px 8px;
    font-size: 12px;
  }
  
  :deep(.el-table td) {
    padding: 10px 8px;
    font-size: 12px;
  }
  
  .product-image {
    width: 48px;
    height: 48px;
  }
  
  .product-name {
    max-width: 100px;
  }
  
  :deep(.el-table .el-button--mini) {
    padding: 3px 6px;
    font-size: 11px;
    margin: 0 2px;
  }
}
</style>